Telegram Group & Telegram Channel
Что выведет следующий код на C#?


using System;

class Program {
static void Main() {
int a = 1000;
int b = 1000;

object x = a;
object y = b;

Console.WriteLine(x == y); // #1
Console.WriteLine(x.Equals(y)); // #2
}
}


🔢 Варианты ответа:

A)

True


B)

False


C)

True


D)

False


Правильный ответ: C

💡 Почему?

-
x и y — boxed значения типа int, то есть ссылки на два разных объекта в куче.
-
x == y сравнивает ссылки, а не значения → False.
-
x.Equals(y) вызывает метод Equals для int, который сравнивает значения → True.

📌 Подвох — в различии
== и .Equals() при использовании упакованных типов.

@csharp_ci



tg-me.com/csharp_ci/1336
Create:
Last Update:

Что выведет следующий код на C#?


using System;

class Program {
static void Main() {
int a = 1000;
int b = 1000;

object x = a;
object y = b;

Console.WriteLine(x == y); // #1
Console.WriteLine(x.Equals(y)); // #2
}
}


🔢 Варианты ответа:

A)

True


B)

False


C)

True


D)

False


Правильный ответ: C

💡 Почему?

-
x и y — boxed значения типа int, то есть ссылки на два разных объекта в куче.
-
x == y сравнивает ссылки, а не значения → False.
-
x.Equals(y) вызывает метод Equals для int, который сравнивает значения → True.

📌 Подвох — в различии
== и .Equals() при использовании упакованных типов.

@csharp_ci

BY C# (C Sharp) programming


Warning: Undefined variable $i in /var/www/tg-me/post.php on line 283

Share with your friend now:
tg-me.com/csharp_ci/1336

View MORE
Open in Telegram


C C Sharp programming Telegram | DID YOU KNOW?

Date: |

What is Telegram Possible Future Strategies?

Cryptoassets enthusiasts use this application for their trade activities, and they may make donations for this cause.If somehow Telegram do run out of money to sustain themselves they will probably introduce some features that will not hinder the rudimentary principle of Telegram but provide users with enhanced and enriched experience. This could be similar to features where characters can be customized in a game which directly do not affect the in-game strategies but add to the experience.

If riding a bucking bronco is your idea of fun, you’re going to love what the stock market has in store. Consider this past week’s ride a preview.The week’s action didn’t look like much, if you didn’t know better. The Dow Jones Industrial Average rose 213.12 points or 0.6%, while the S&P 500 advanced 0.5%, and the Nasdaq Composite ended little changed.

C C Sharp programming from hk


Telegram C# (C Sharp) programming
FROM USA